<style>
  .picImg {
    width: 40px;
    height: 40px;
  }
</style>
<template>
  <div class="app-container">
    <div class="filter-container">
      <el-date-picker
        v-model="listQuery.startTime"
        type="datetime"
        placeholder="查询开始日期"
        value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
      -
      <el-date-picker
        v-model="listQuery.endTime"
        type="datetime"
        placeholder="查询结束日期"
        value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
      <el-select v-model="listQuery.agentID" placeholder="保代/权益服务商">
        <el-option
          v-for="item in options"
          :key="item.ID"
          :label="item.companyName"
          :value="item.ID">
        </el-option>
      </el-select>
      <!--<el-input v-model="listQuery.agentID" placeholder="保公司/权益服务商ID" style="width: 300px"/>-->
      <el-select v-model="listQuery.factoringID" placeholder="请选择保理公司">
        <el-option
          v-for="item in options2"
          :key="item.ID"
          :label="item.companyName"
          :value="item.ID">
        </el-option>
      </el-select>
      <el-button @click="getInput">查询</el-button>
    </div>
    <!--&lt;!&ndash; 查询和其他操作 &ndash;&gt;-->
    <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row
              :header-cell-style="{background:'#92D3FF',color:'#fff'}">
      <!--<el-table-column align="center" min-width="100" label="备注" prop="remark"/>-->
      <el-table-column align="center" min-width="100" label="表单编号" prop="formNo"/>
      <el-table-column align="center" min-width="100" label="回款金额 (元)" prop="amount"/>
      <el-table-column align="center" min-width="100" label="回款时间" prop="repayTime"/>
      <el-table-column align="center" min-width="100" label="保险公司名称" prop="suranceName"/>
      <el-table-column align="center" min-width="100" label="保代公司名称" prop="agentName"/>
      <el-table-column align="center" min-width="100" label="保理公司名称" prop="factoringName"/>
      <el-table-column align="center" min-width="100" label="关联类型" prop="formType">
        <template slot-scope="scope">
          <el-tag>{{{"0":"保代公司","1":"权益服务商"}[scope.row.formType]}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" min-width="100" label="保单总数" prop="billCount"/>
      <el-table-column align="center" min-width="100" label="手续费总额 (元)" prop="amount"/>
      <el-table-column align="center" min-width="100" label="上传备注" prop="remarkUp"/>
      <!--<el-table-column fixed="right" align="center" label="操作" width="250" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary" size="mini"
                     @click="detail(scope.row)">表单详情
          </el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <el-dialog :visible.sync="editDialogVisible" title="明细列表" :close-on-click-modal="false">
      <el-table v-loading="listLoading1" :data="list1" element-loading-text="正在查询中。。。" border fit highlight-current-row
                :header-cell-style="{background:'#92D3FF',color:'#fff'}">

        <el-table-column align="center" min-width="100" label="保单号或合同号" prop="billNo"/>
        <el-table-column align="center" min-width="100" label="保单金额 (元)" prop="billAmount"/>
        <el-table-column align="center" min-width="100" label="代理手续费" prop="fee"/>
        <el-table-column align="center" min-width="100" label="代理人身份证号" prop="agentID"/>
        <el-table-column align="center" min-width="100" label="代理人编码" prop="agentNo"/>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editDialogVisible = false">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {doGet, doPost} from '@/api'
  import {cities} from '@/utils/base'
  import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

  export default {
    name: 'bank',
    components: {Pagination},
    filters: {},
    data() {
      return {
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        },
        options: [],
        options2: [],
        list: [],
        list1: [],
        total: 0,
        listLoading: true,
        listLoading1: true,
        listQuery: {
          startTime: undefined,
          endTime: undefined,
          agentID: undefined,
          factoringID: undefined
        },
        editForm: {
          id: undefined,
          billNo: undefined,
          billAmount: undefined,
          fee: undefined,
          agentID: undefined,
          agentNo: undefined,
            formType: undefined,
        },
        editDialogVisible: false,
      }
    },
    created() {
      this.getList()
      this.getCompanyList()
      doGet('factoring.html?op=list', {})
        .then(response => {
          this.options2 = response.rows
        })
        .catch(response => {
          this.options2 = []
        })
    },
    methods: {
        getCompanyList() {
            doGet('insurance.html?op=getCompanyList', {companyType: '1,2'})
                .then(response => {
                    this.options = response.rows
                })
                .catch(response => {
                    this.options = []
                })
        },
      getList() {
        this.listLoading = true
        doGet('repaysearch.html?op=list', this.listQuery).then(response => {
          this.list = response.rows
          this.total = response.rows.length
          this.listLoading = false
        }).catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
      },
      getInput() {
        this.getList()
      },
      detail(row) {
        this.editDialogVisible = true
        this.listLoading1 = true
          this.editForm1 ={
              id: row.id,
              formType: row.formType,
          }
//        console.log(row.id)
        doGet('repaysearch.html?op=billlist', this.editForm1).then(response => {
          console.log(response);
          this.list1 = response.rows
          this.listLoading1 = false
//          this.editForm.id = response.rows.id;
//          this.editForm.billNo = response.rows.billNo;
//          this.editForm.billAmount = response.rows.billAmount;
//          this.editForm.fee = response.rows.fee;
//          this.editForm.agentID = response.rows.agentID;
//          this.editForm.agentNo = response.rows.agentNo
        }).catch(() => {
          this.list = [];
          this.total = 0;
          this.listLoading1 = false
        })
      },
    }
  }
</script>
